﻿/****************************************************************************
** \file ParamProcesser.cpp
** \company PONGBOT
**
** \author houhaotian
** \date 2020/08/26
**
** \brief 读取所有元对象的属性，按照<对象名/属性名,QVariant>的方式存到QSettings.
**        在设置objectname的时候自动读取内容，在属性变更时自动保存值。
**
**
****************************************************************************/
#pragma once
#include <QObject>

class QSettings;
class QTimer;

class ParamProcesser : public QObject
{
    Q_OBJECT

public:
    explicit ParamProcesser(QObject *parent = nullptr);
    virtual ~ParamProcesser();

    QStringList allPropertiesName();

protected:
    virtual void saveProperties();
    void saveProperty(const char *property);

private:
    Q_SLOT void onObjectNameChanged(const QString &objectName);

private:
    QSettings *m_settings;
    QTimer *m_timer;
    Q_DISABLE_COPY(ParamProcesser)
};

/*!
 *  连接属性变化NOTIFY信号，发出带有属性名的信号。
*/
class ReceiverPrivate : public QObject
{
	Q_OBJECT

public:
    explicit ReceiverPrivate(const char *property, QObject *parent);

signals:
	void propertyChanged(const char *property);

public slots:
    void onPropertyChanged() {
        emit propertyChanged(m_property);
    }

private:
	const char *const m_property;
};
